<!-- 说说部分 2023-10-30 -->
 <style>

        /*模态框主体样式*/
        .modal {
	
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.5);
        }

        /*模态框公共样式*/
        .modal-content {
				border-radius: 10px;	
            background-color: #fefefe;
            margin: 50px auto 0;
            padding: 20px;
            border: 1px solid #888;
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
            animation: modal-show 0.3s;
        }

        /* 正常大小 */
        .modal-normal {
            width: 600px;
        }

        /* 中等大小 */
        .modal-medium {
            width: 400px;
        }

        /* 迷你大小 */
        .modal-mini {
            width: 250px;
        }

        /* 隐藏 */
        .modal-hide {
            animation: modal-hide 0.3s;
        }

        /* 展示动画 */
        @keyframes modal-show {
            from {
                opacity: 0;
                transform: translateY(-50px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 隐藏动画 */
        @keyframes modal-hide {
            from {
                opacity: 1;
                transform: translateY(0);
            }
            to {
                opacity: 0;
                transform: translateY(-50px);
            }
        }

        /*关闭按钮*/
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            -webkit-tap-highlight-color: rgba(255,0,0,0);
        }

        /*关闭按钮的鼠标点击和经过样式*/
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
            -webkit-tap-highlight-color: rgba(255,0,0,0);
        }
    </style>
<style>
	.btnwidth{
		width: 100px;
	}
</style>
<button data-modal-action="open" data-modal-target="myModal" class="mybtn btnwidth">新加说说</button>
<!-- 模态框部分 新加-->
<div id="myModal" class="modal">
        <div class="modal-content modal-normal">
            <span class="close">&times;</span>
            <h3 align="center">新加说说</h3>
           <form class="form-horizontal" method="post" action="/addcontextc?name={{name}}" enctype="multipart/form-data">
   <input type="hidden" value="{{name}}" name="uname">
               <div class="form-group row">
                 <label for="inputExperience" class="col-sm-2 col-form-label">说说内容</label>
                 <div class="col-sm-10">
                   <textarea class="form-control" id="inputExperience" name="context" placeholder="请在这边写说说"></textarea>
                 </div>		
               </div>

               <div class="form-group row">
				     <div class="form-group">
				                     <div class="btn btn-default btn-file">
				                       <i class="fas fa-paperclip"></i> 添加附件
				                       <input type="file" onchange="showImg(this)" name="attachment">
				                     </div>
				                     <p class="help-block">不超过:20MB</p>
				                   </div>
						   <div id="imgContainer" style="margin-top: 10px;"></div>
                 <div class="offset-sm-2 col-sm-10">
                   <button type="submit" class="btn btn-success">添加</button>
				  <button type="reset" class="btn btn-success" onclick="clearadd()">重置</button>
                 </div>
               </div>
           </form>
			   <!-- 新加，头像说说的js-->
			   <script type="text/javascript">
				   //新加说说有关的
			     function showImg(obj) {
			       var files = obj.files
			       document.getElementById("imgContainer").innerHTML = getImgsByUrl(files)
			       // getImgsByFileReader(document.getElementById("imgContainer"), files)
			     }
				
				 //新加说说
			     function getImgsByUrl(files) {
			       var elements = ''
			       for (var i = 0; i < files.length; i++) {
			         var url = window.URL.createObjectURL(files[i])
			         elements += "<img src='" + url + "' style='width: 40%; height: 40%;' class='addimg'/>"
			       }
			       return elements
			     }
				 
				 //清除修改图片
				 function clearadd(){
					 try{
						 var addimg = document.getElementsByClassName('addimg')
						 addimg.item(addimg).remove()
					 }catch(e){
					 	//TODO handle the exception
					 }
					 
				 }
				
			   </script>
			   <script>
			   
			       // 获取触发模态框的自定义属性
			       var modalButtons = document.querySelectorAll("[data-modal-action]");
			   
			       // 获取模态框主体
			       var modals = document.querySelectorAll(".modal");
			   
			       // 监听模态框的按钮事件
			       modalButtons.forEach(function(button) {
			           button.addEventListener("click", function() {
			               var targetId = this.dataset.modalTarget;
			               var targetModal = document.getElementById(targetId);
			   
			               if (targetModal) {
			                   var action = this.dataset.modalAction;
			   
			                   if (action === "open") {
			                       openModal(targetModal);
			                   } else if (action === "close") {
			                       closeModal(targetModal);
			                   }
			               }
			           });
			       });
			   
			       // 打开模态框
			       function openModal(modal) {
			           modal.style.display = "block";
			           modal.querySelector(".modal-content").classList.remove("modal-hide");
			       }
			   
			       // 关闭模态框
			       function closeModal(modal) {
			           modal.querySelector(".modal-content").classList.add("modal-hide");
			           modal.querySelector(".modal-content").addEventListener("animationend", function () {
			               modal.style.display = "none";
			           }, { once: true });
			       }
			   
			       // 监听模态框的关闭时事件
			       modals.forEach(function(modal) {
			           var closeButton = modal.querySelector(".close");
			           if (closeButton) {
			               closeButton.addEventListener("click", function() {
			                   var targetModal = this.closest(".modal");
			                   closeModal(targetModal);
			               });
			           }
			       });
			   
			       // 当用户点击模态框外部时，关闭模态框
			     //   window.onclick = function (event) {
					   // // console.log('点击了')
			     //       modals.forEach(function(modal) {
			     //           if (event.target === modal) {
			     //               closeModal(modal);
			     //           }
			     //       });
			     //   };
	            window.addEventListener('click', function(event) {
	                 modals.forEach(function(modal) {
	                     if (event.target === modal) {
	                         closeModal(modal);
	                     }
	                 });
	               });
			   </script>